﻿using System.Windows;
using System.Windows.Controls;
using ViewModel.Models;

namespace Views.TemplateSelector
{
    public class ChatListBoxTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var fe = container as FrameworkElement;
            var obj = item as ChatMessageItem;
            DataTemplate dt = null;
            if (obj != null && fe != null)
            {
                switch (obj.MessageOwner)
                {
                    case ClientModels.MessageOwner.Self:
                        {
                            switch (obj.MessageType)
                            {
                                case ClientModels.MessageType.文本消息:
                                    {
                                        dt = fe.FindResource("SelfMessage") as DataTemplate;

                                        break;
                                    }

                                case ClientModels.MessageType.文件信息:
                                    {
                                        dt = fe.FindResource("SelfFile") as DataTemplate;
                                        break;
                                    }
                            }
                            break;
                        }
                    case ClientModels.MessageOwner.Friend:
                        {
                            switch (obj.MessageType)
                            {
                                case ClientModels.MessageType.文本消息:
                                    {
                                        dt = fe.FindResource("FriendMessage") as DataTemplate;

                                        break;
                                    }

                                case ClientModels.MessageType.文件信息:
                                    {
                                        dt = fe.FindResource("FriendFile") as DataTemplate;
                                        break;
                                    }
                            }
                            break;
                        }
                }
            }
            return dt;
        }
    }
}